package com.uenpay.im.invokeitems.person;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.qiyunxin.android.http.utils.StringUtils;
import com.uenpay.im.configuration.APIConfiguration;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 
 *  @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class UpdateInfoInvokItem extends HttpInvokeItem {

	public class UpdateInfoInvokItemResult {
		public int status;
		public String msg;
	}

	public UpdateInfoInvokItemResult getOutput() {
		return (UpdateInfoInvokItemResult) GetResultObject();
	}

	public UpdateInfoInvokItem(String field, String value) {
		String pattern = APIConfiguration.getBaseUrl()
				+ "Cust/Cust/saveCustInfoByField?field=" + field + "&value="
				+ StringUtils.encodeParams(value) + "&" + APIConfiguration.getCustIdAndToken();
		SetUrl(pattern);
	}

	@Override
	protected Object DeserializeResult(String responseBody) throws Exception {
		UpdateInfoInvokItemResult result = new UpdateInfoInvokItemResult();

		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
		} catch (JSONException e) {
			return result;
		}
		return result;
	}

}
